#!/bin/bash
# 起在hadoop162一个nginx,在162-164分别起一个日志服务器
nginx_home=/opt/module/nginx
log_home=/opt/module/gmall0621
case $1 in
"start")
    # 先启动nginx
    if [ -z "$(ps -ef | awk '/nginx/ && !/awk/ {print $0}')" ]; then
        echo "在 hadoop162 开始启动nginx"
        $nginx_home/sbin/nginx
    else
        echo "在 hadoop162 nginx已经启动,不用重复启动"
    fi
    # 分别启动日志服务器
    for host in hadoop162 hadoop163 hadoop164 ; do
        echo "在${host}上启动日志服务器"
        ssh $host "nohup java -jar $log_home/gmall-logger-0.0.1-SNAPSHOT.jar >/dev/null 2>&1 &"
    done
;;
"stop")
    echo "在 hadoop162 停止nginx"
    $nginx_home/sbin/nginx -s stop
    # 分别停止日志服务器
    for host in hadoop162 hadoop163 hadoop164 ; do
        echo "在${host}上停止日志服务器"
        ssh $host "jps | awk '/gmall-logger-0.0.1-SNAPSHOT.jar/ {print \$1}' | xargs kill -9"
    done

;;

*)
    echo "你启动的姿势不对, 换个姿势再来"
    echo "  log.sh start 启动日志采集"
    echo "  log.sh stop  启动日志采集"
;;
esac


